<template>
	<div>
		<el-dialog
			:title="'添加'+titleName"
			:visible.sync="dialogVisible"
			width="50%"
			:before-close="handleClose"
			@close="DialdgClose"
		>
			<!-- 内容区域 -->
			<el-form :model="FormData" :rules="FormRules" ref="FormRef" label-width="110px">
				<el-form-item :label="titleName +'名称:'" prop="ParamName">
					<el-input v-model="FormData.ParamName"></el-input>
				</el-form-item>
			</el-form>

			<!-- 底部区域 -->
			<span slot="footer" class="dialog-footer">
				<el-button @click="dialogVisible = false">取 消</el-button>
				<el-button type="primary" @click="save">确 定</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
export default {
	props: {
		//是否弹出
		dialogVisible: {
			type: Boolean,
			default: false
        },
        //标题名称
        titleName:{
            type:String,
            default:''
        },
        CateID:{
            type:parseInt,
            default:0
        },
        Type:{
            type:parseInt,
            default:0
        }
        
	},
	data() {
		return {
			FormData: {
                Id:0,
                ParamName: '',
                Type:0,
                CateId:0
			},
			FormRules: {
				ParamName: [
					{
						required: true,
						message: '请输入'+this.titleName+'名称',
						trigger: 'blur'
					}
				]
			}
		}
	},
	methods: {
		handleClose(done) {
			this.$confirm('确认关闭？')
				.then(_ => {
					done()
				})
				.catch(_ => {})
		},
		//监听关闭添加用户的对话框事件
		DialdgClose() {
			this.$refs.FormRef.resetFields()
		},
		save() {
			this.$refs.FormRef.validate(valid => {
				if (valid) {
                    this.FormData.CateId=this.CateID;
                    this.FormData.Type=this.Type;
					this.$get('/api/Params/AddParams',this.FormData).then(res=>{
                        if(res.code==0){
                            this.$emit('dateupdata')
                            this.$message({
                                message:res.msg,
                                type:"success"
                            })
                            this.dialogVisible=false
                        }else{
                            this.$message.error(res.msg)
                        }
                    }).catch(err=>{
                        console.log(err)
                    })
				} else {
					console.log('error submit!!')
					return false
				}
			})
		}
	},
	watch: {
		dialogVisible: function(val) {
			let data = {
				IsShow: val
            }
			this.$emit('IsShowDialdg', data)
		}
	}
}
</script>